const Express = require("express");
const SymptomServer = require('../../servers/Symptom');
const ResponseHelper = require("../ResponseHelper");
const router = Express.Router();



/**
 * 获取所有症状
 */
router.get("/getAllSymptom",async(req,res)=>{
    try {
        const result = await SymptomServer.getAll();
        ResponseHelper.sendData(result, res);
      } catch (err) {
        ResponseHelper.sendErr(err, res);
      }
})

/**
 * 批量添加症状
 */
 router.post("/bulkCreateSymptom", async (req, res) => {
    try {
      const result = await SymptomServer.bulkCreate(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

/**
 * 添加症状
 */
 router.post("/addSymptom", async (req, res) => {
    try {
      const result = await SymptomServer.add(req.body);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});


/**
 * 更新症状
 */
 router.post("/updateSymptom/:id", async (req, res) => {
    try {
      const id =  req.params.id;
      const result = await SymptomServer.update(id);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});

/**
 * 根据id获取症状
 */
 router.post("/getSymptom/:id", async (req, res) => {
    try {
      const id =  req.params.id;
      const result = await SymptomServer.getById(id);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});


/**
 * 根据id删除症状
 */
 router.post("/delSymptom/:id", async (req, res) => {
    try {
      const id =  req.params.id;
      const result = await SymptomServer.delete(id);
      ResponseHelper.sendData(result, res);
    } catch (err) {
      ResponseHelper.sendErr(err, res);
    }
});
/**
 * 根据title获取症状
 */
router.post("/getSymptomByTitle", async (req, res) => {
  try {
    const { title } = req.body;
    const result = await SymptomServer.getSymptomByTitle(title);
    ResponseHelper.sendData(result, res);
  } catch (err) {
    ResponseHelper.sendErr(err, res);
  }
});

module.exports = router;